import Content from '@/sheep/layouts/content.vue';
import { request } from '@/sheep/request';
import { CRUD } from '@/sheep/request/crud';
import { EXPORT } from '@/sheep/request/export';

const route = {
  path: 'order',
  name: 'shop.admin.order',
  component: Content,
  meta: {
    title: '订单',
  },
  children: [
    {
      path: 'order',
      name: 'shop.admin.order.order',
      component: () => import('@/app/shop/admin/order/order/index.vue'),
      meta: {
        title: '订单管理',
      },
    },
    {
      path: 'aftersale',
      name: 'shop.admin.order.aftersale',
      component: () => import('@/app/shop/admin/order/aftersale/index.vue'),
      meta: {
        title: '售后管理',
      },
    },
    {
      path: 'invoice',
      name: 'shop.admin.order.invoice',
      component: () => import('@/app/shop/admin/order/invoice/index.vue'),
      meta: {
        title: '订单发票',
      },
    },
  ],
};

const api = {
  order: {
    ...CRUD('shop/admin/order/order', ['list', 'detail', 'edit']),
    getType: () =>
      request({
        url: '/shop/admin/order/order/getType',
        method: 'GET',
      }),
    action: (id) =>
      request({
        url: `/shop/admin/order/order/action/${id}`,
        method: 'GET',
      }),
    // 发货
    dispatch: (data) =>
      request({
        url: '/shop/admin/order/order/dispatch',
        method: 'POST',
        data,
      }),
    // 导出
    export: (type, params) => EXPORT(`/shop/admin/order/order/${type}`, params),
    // 上传发货单发货
    dispatchByUpload: (data) =>
      request({
		timeout:60000,
        url: '/shop/admin/order/order/dispatch',
        headers: {
          'Content-Type': 'multipart/form-data',
        },
        method: 'POST',
        data,
      }),
    customDispatch: (data) =>
      request({
        url: '/shop/admin/order/order/customDispatch',
        method: 'POST',
        data,
      }),
    editMemo: (id, data) =>
      request({
        url: `/shop/admin/order/order/editMemo/${id}`,
        method: 'PUT',
        data,
      }),
    applyRefundRefuse: (id) =>
      request({
        url: `/shop/admin/order/order/applyRefundRefuse/${id}`,
        method: 'PUT',
      }),
    fullRefund: (id, data) =>
      request({
        url: `/shop/admin/order/order/fullRefund/${id}`,
        method: 'PUT',
        data,
      }),
    refund: (id, item_id, data) =>
      request({
        url: `/shop/admin/order/order/refund/${id}/${item_id}`,
        method: 'PUT',
        data,
      }),
    updateExpress: (id, params) =>
      request({
        url: `/shop/admin/order/order/updateExpress/${id}`,
        method: 'GET',
        params,
      }),
    changeFee: (id, data) =>
      request({
        url: `/shop/admin/order/order/changeFee/${id}`,
        method: 'PUT',
        data,
      }),
    editConsignee: (id, data) =>
      request({
        url: `/shop/admin/order/order/editConsignee/${id}`,
        method: 'PUT',
        data,
      }),
    offlineRefuse: (id) =>
      request({
        url: `/shop/admin/order/order/offlineRefuse/${id}`,
        method: 'POST',
      }),
    offlineConfirm: (id) =>
      request({
        url: `/shop/admin/order/order/offlineConfirm/${id}`,
        method: 'POST',
      }),
  },
  aftersale: {
    ...CRUD('shop/admin/order/aftersale', ['list', 'detail']),
    getType: () =>
      request({
        url: '/shop/admin/order/aftersale/getType',
        method: 'GET',
      }),
    refuse: (id, params) =>
      request({
        url: `/shop/admin/order/aftersale/refuse/${id}`,
        method: 'PUT',
        params,
      }),
    refund: (id, params) =>
      request({
        url: `/shop/admin/order/aftersale/refund/${id}`,
        method: 'PUT',
        params,
      }),
    completed: (id) =>
      request({
        url: `/shop/admin/order/aftersale/completed/${id}`,
        method: 'PUT',
      }),
    addLog: (id, data) =>
      request({
        url: `/shop/admin/order/aftersale/addLog/${id}`,
        method: 'PUT',
        data,
      }),
  },
  invoice: {
    ...CRUD('shop/admin/order/invoice', ['list']),
    confirm: (id, data) =>
      request({
        url: '/shop/admin/order/invoice/confirm/' + id,
        method: 'PUT',
        data,
      }),
  },
};

export { route, api };
